import java.util.Arrays;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        int ret = Arrays.binarySearch(arr, 5);
        System.out.println(ret);
        System.out.println(Arrays.toString(arr));
    }
    public static boolean binarySearch(int[]arr,int val){
        int left = 0,right = arr.length-1;
        while (left <= right){
            int mid = (left + right) /2;
            if (arr[mid] > val){
                right = mid - 1;
            }else if (arr[mid] < val){
                left = mid + 1;
            }else {
                return true;
            }
        }
        return false;
    }

    public static void main9(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        Scanner scanner = new Scanner(System.in);
        int val= scanner.nextInt();
        boolean ret = binarySearch(arr, val);
        if (ret){
            System.out.println("找到了:"+val);
        }else {
            System.out.println("没有找到:"+val);
        }
    }


    /*
    查找数组中是否含有 val 这个值
     */
    public static boolean search(int[] arr,int val){
        for (int i = 0;i<arr.length;i++){
            if (arr[i] == val){
                return true;
            }
        }
        return false;
    }
    public static void main8(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        Scanner scanner = new Scanner(System.in);
        int val= scanner.nextInt();
        boolean ret = search(arr, val);
        if (ret){
            System.out.println("找到了:"+val);
        }else {
            System.out.println("没有找到:"+val);
        }

    }
    public static int[] func2(int[]array){
        int[] tmp = new int[array.length];
        for (int i=0;i<array.length;i++){
            tmp[i] = array[i];
        }
        return tmp;
    }

    public static void main7(String[] args) {
        int[] arr = {1,2,3,4,5};
        int[] ret = func2(arr);
        for (int x : ret){
            System.out.println(x);
        }
    }
    /**
     * 将 array 这个数组的每个值都扩大两倍
     * @param array
     * @return 返回扩大完的数组
     */
    public static int[] func(int[]array){
        int[] ret = new int[array.length];
        for (int i = 0;i<array.length;i++){
            ret[i] = array[i] * 2;
        }
        return ret;
    }

    public static void main6(String[] args) {
        int[] arr = {1,2,3,4,5};
        int[] ret = func(arr);
        for (int x : ret){
            System.out.println(x);
        }
    }
    public static void main5(String[] args) {
        int[] arr = null;
        System.out.println(arr[0]);
    }
    public static void main4(String[] args) {
        int[] array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;
        int[] array2 = new int[]{1,2,3,4,5};
        array2[0] = 100;
        array2[1] = 200;
        array1 = array2;
        array1[2] = 300;
        array1[3] = 400;
        array2[4] = 500;
        for (int i = 0; i < array2.length; i++) {
            System.out.println(array2[i]);
        }
    }
    public static void main3(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        System.out.println(arr);
        Thread t = new Thread();
        t.start();
//        System.out.println(arr[0]);
//        System.out.println(arr[2]);
//        System.out.println(arr[5]);
//        System.out.println(arr[6]);

    }
    public static void main2(String[] args) {
        int[] arr = new int[10];
//        for (int i = 0; i < arr.length; i++) {
//            System.out.print(arr[i] );
//        }
        for(int x : arr){
            System.out.print(x + " ");
        }
    }
    public static void main1(String[] args) {
        // 5 个 同学的成绩
        int score = 100;
        int score2 = 90;
        int score3 = 80;
        int score4 = 100;
        int score5 = 100;
        //int[] arr = new int[10];
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        int[] array1 = new int[]{1,2,3,4,5,6,7,8,9,10};
        String[] arr = new String[10];
        double[] arr2= new double[10];
    }
}